package com.lee.crawler.gov.strategy;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.safety.Whitelist;
import org.springframework.stereotype.Component;

@Component
public class FuzhouArticleStrategy extends AbstractArticleStrategy {

	private static final DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

	@Override
	public String getTitle(Document content) {
		return content.selectFirst("h3,h4").text();
	}

	@Override
	public Timestamp getPublishedTime(Document content) {
		String pubDate = content.selectFirst("meta[name=pubDate]").attr("content");
		LocalDateTime localDateTime = LocalDateTime.parse(pubDate.replaceAll("[ ]+", " "), ofPattern);
		return Timestamp.valueOf(localDateTime);
	}

	@Override
	public String getContent(Document content) {
		return content.selectFirst(".TRS_Editor,#detailCon,.box1").text();
	}

	@Override
	public String getHtmlContent(Document content) {
		Element htmlContentEl = content.selectFirst(".TRS_Editor,#detailCon,.box1");
		String htmlContent = Jsoup.clean(htmlContentEl.html(), Whitelist.relaxed());
		return htmlContent;
	}

}
